package com.xiaowen.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * 消费者
 * 监听服务器上的kafka是否有相关的消息发过来
 * @author xiaowen
 *
 */
@Component
public class ConsumerKafka {

	//定义此消费者接收topics = "test"的消息，与ProducerKafkaController中的topic对应上即可
	@KafkaListener(topics = "test")
    public void listen (ConsumerRecord<?, ?> record) throws Exception {
        System.out.printf("topic = %s, offset = %d, value = %s \n", record.topic(), record.offset(), record.value());
    }
}
